#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <stdio.h>
#include <string.h>

#include "drivers/ws2812b.h"
#include "modules/rgb_mode.h"

#define WS2812B_RGB_CNT       18
#define WS2812B_FRAME_MAX_CNT 64

static uint32_t frame[WS2812B_FRAME_MAX_CNT][WS2812B_RGB_CNT];

void app_main(void)
{
	int i = 0;
	int frm_cnt = 0;
	rgb_anim_t anim;

	ws2812b_init();

	while (1) {
		frm_cnt = rgb_water_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = 0xff0000;
			anim.frm_num = i;
			rgb_water_frame_get(&anim, frame[i]);
			ws2812b_write(frame[i], WS2812B_RGB_CNT);
			vTaskDelay(33 / portTICK_PERIOD_MS);
		}

		frm_cnt = rgb_water_opposite_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = 0xff0000;
			anim.frm_num = i;
			rgb_water_opposite_frame_get(&anim, frame[i]);
			ws2812b_write(frame[i], WS2812B_RGB_CNT);
			vTaskDelay(33 / portTICK_PERIOD_MS);
		}

		frm_cnt = rgb_sequentially_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = 0xff0000;
			anim.frm_num = i;
			rgb_sequentially_frame_get(&anim, frame[i]);
			ws2812b_write(frame[i], WS2812B_RGB_CNT);
			vTaskDelay(33 / portTICK_PERIOD_MS);
		}

		frm_cnt = rgb_sequentially_opposite_frame_count_get(WS2812B_RGB_CNT);
		for (i = 0; i < frm_cnt; i++) {
			anim.led_cnt = WS2812B_RGB_CNT;
			anim.color = 0xff0000;
			anim.frm_num = i;
			rgb_sequentially_opposite_frame_get(&anim, frame[i]);
			ws2812b_write(frame[i], WS2812B_RGB_CNT);
			vTaskDelay(33 / portTICK_PERIOD_MS);
		}
	}
}
